// bookgo/index/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        rules: [],
        
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log('++++++++++++++++onLoad--->options++++++++++++++++');
        console.log(options);
        this.get_message();
        var that = this;
        // var aid = wx.getStorageSync('aid');
        var scene = decodeURIComponent(options.scene);
        console.log(scene);
        if (scene != 'undefined') {
        var scene_data = scene.split(',');
        console.log('-----------scene_data-----------');
        console.log(scene_data);
            wx.redirectTo({
                url: '/' + scene_data[0] + '?id=' + scene_data[1],
            });
        }
    },



    
    get_message: function () {
        const that = this;
        var _t = (new Date()).getTime();
        wx.request({
        url: 'https://2016.bookgo.com.cn/wxapp/index/get_index_rules',
        data: {},
        header: {
            'content-type': 'application/json'
        },
        success: function (res) {
            console.log(res.data);
            var data = res.data;
            var items = []
            for (var i = 0; i < data.length; i++) {
            var item = {
                text: data[i].text
            };
            items.push(item);
            }
            console.log(items)
            that.setData({
            rules: items
            });
        },
        fail: function (res) {

        },
        complete: function () {

        }
        });
    },
    scan_code:function(){
        const that = this;
        wx.scanCode({
            onlyFromCamera: true,
            success: (res) => {
                console.log('-------res里是什么玩意---------');
                console.log(res);
                if (res.path) {
                    wx.redirectTo({
                        url: '/' + res.path,
                    });
                } else {
                    wx.showModal({
                        title: '提示',
                        content: '该二维码不是小程序码，请使用微信自带扫码扫描该二维码。',
                        showCancel: false,
                        success: function (res) {
                        console.log(res);
                        }
                    })
                }
            }
        });
    },
        go_ifan:function(){
        wx.redirectTo({
        url: '/bookgo/fan/ifan/ifan',
        })
    },

        go_iborrow:function(){  
            wx.redirectTo({
                url: '/bookgo/public_login/public_login',
            });
        
        },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
    
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
    
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
    
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
    
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
    
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
    
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
    
    }
})